package com.netease.spring.jdbc;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mysql.jdbc.Connection;

public class Main {
    public static void main(String[] args) throws SQLException,
            ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn1 = (Connection) DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test", "root", "55555");
        Statement st1 = conn1.createStatement();
        ResultSet rs1 = st1.executeQuery("select * from user");
        while (rs1.next()) {
            System.out.println(rs1.getString(2));
        }
        rs1.close();
        st1.close();
        conn1.close();

        ApplicationContext ac2 = new ClassPathXmlApplicationContext("jdbc.xml");
        DataSource ds2 = (DataSource) ac2.getBean("dataSource");
        java.sql.Connection conn2 = ds2.getConnection();
        Statement st2 = conn2.createStatement();
        ResultSet rs2 = st2.executeQuery("select * from user");
        while (rs2.next()) {
            System.out.println(rs2.getString(2));
        }
        rs2.close();
        st2.close();
        conn2.close();
    }
}
